String clazzTpl({package}) => """
import 'dart:ui';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:$package/route/main.route.dart';

/// 请叫我code哥
/// Generates Dart code
class Toast {
  static OverlayEntry? _overlayEntry, _overlayEntryTips, _overlayEntryLoading;
  static bool _showing = false, _showingTips = false, _showLoading = false;
  static DateTime? _startedTime, _startedTimeTips, _startedTimeLoading;
  static int _duration = 2000;
  static String? _msg;

  static void show(String msg, {double top = 0.0}) async {
    _msg = msg;
    _startedTime = DateTime.now();

    OverlayState overlayState = globalNavigatorKey.currentState!.overlay!;
    _showing = true;
    if (_overlayEntry == null) {
      _overlayEntry = OverlayEntry(
          builder: (BuildContext context) => Positioned(
                top: top > 0 ? top : MediaQuery.of(context).size.height * 1 / 4,
                child: Container(
                    padding: EdgeInsets.all(80),
                    alignment: Alignment.center,
                    width: MediaQuery.of(context).size.width,
                    child: Container(
                      alignment: Alignment.center,
                      width: 210,
                      height: 68,
                      decoration: BoxDecoration(
                          color: Colors.black.withOpacity(0.7),
                          borderRadius: BorderRadius.all(Radius.circular(6))),
                      padding: EdgeInsets.only(
                          left: 10, right: 10, top: 5, bottom: 5),
                      child: AnimatedOpacity(
                        opacity: _showing ? 1.0 : 0.0,
                        duration: _showing
                            ? Duration(milliseconds: 100)
                            : Duration(milliseconds: 400),
                        child: Text(
                          _msg!,
                          style: TextStyle(
                            fontSize: 13.0,
                            decoration: TextDecoration.none,
                            fontWeight: FontWeight.normal,
                            color: Colors.white,
                          ),
                        ),
                      ),
                    )),
              ));
      Future.delayed(Duration.zero, () {
        overlayState.insert(_overlayEntry!);
      });
    } else {
      if (_overlayEntry != null) {
        Future.delayed(Duration.zero, () {
          _overlayEntry?.markNeedsBuild();
        });
      }
    }
    await Future.delayed(Duration(milliseconds: _duration)); //等待3秒

    if (DateTime.now().difference(_startedTime!).inMilliseconds >= _duration) {
      _showing = false;
      if (_overlayEntry != null) {
        Future.delayed(Duration.zero, () {
          _overlayEntry?.markNeedsBuild();
          _overlayEntry?.remove();
          _overlayEntry = null;
        });
      }
    }
  }

  static void close() {
    _showing = false;
    if (_overlayEntry != null) {
      Future.delayed(Duration.zero, () {
        _overlayEntry?.markNeedsBuild();
        _overlayEntry?.remove();
        _overlayEntry = null;
      });
    }
  }

  static void closeLoading() {
    _showLoading = false;
    if (_overlayEntryLoading != null) {
      Future.delayed(Duration.zero, () {
        _overlayEntryLoading?.markNeedsBuild();
        _overlayEntryLoading?.remove();
        _overlayEntryLoading = null;
      });
    }
  }

  static void showLoading({duration = 15000}) async {
    OverlayState overlayState = globalNavigatorKey.currentState!.overlay!;
    _startedTimeLoading = DateTime.now();
    _showLoading = true;
    if (_overlayEntryLoading == null) {
      _overlayEntryLoading = OverlayEntry(
          builder: (BuildContext context) => Positioned(
                top: MediaQuery.of(context).size.height * 1 / 3,
                child: Container(
                  padding: EdgeInsets.all(80),
                  alignment: Alignment.center,
                  width: MediaQuery.of(context).size.width,
                  child: BlurRectWidget(
                    color: Colors.black.withOpacity(0.7),
                    child: Container(
                      padding: EdgeInsets.all(30),
                      width: 135,
                      child: AnimatedOpacity(
                          opacity: _showLoading ? 1.0 : 0.0,
                          duration: _showLoading
                              ? Duration(milliseconds: 100)
                              : Duration(milliseconds: 400),
                          child: Column(
                            children: [
                              LoadingWidget(),
                              Padding(
                                padding: EdgeInsets.only(
                                    top: 14),
                                child: Text(
                                  'loading...',
                                  style: TextStyle(
                                    fontSize: 14,
                                    color: Colors.white,
                                    fontWeight: FontWeight.normal,
                                    decoration: TextDecoration.none,
                                  ),
                                ),
                              ),
                            ],
                          )),
                    ),
                  ),
                ),
              ));
      Future.delayed(Duration.zero, () {
        overlayState.insert(_overlayEntryLoading!);
      });
    } else {
      if (_overlayEntryLoading != null) {
        Future.delayed(Duration.zero, () {
          _overlayEntryLoading?.markNeedsBuild();
        });
      }
    }
    Future.delayed(Duration(milliseconds: duration), () {
      if (DateTime.now().difference(_startedTimeLoading!).inMilliseconds >=
          duration) {
        _showLoading = false;
        if (_overlayEntryLoading != null) {
          Future.delayed(Duration.zero, () {
            _overlayEntryLoading?.markNeedsBuild();
            _overlayEntryLoading?.remove();
            _overlayEntryLoading = null;
          });
        }
      }
    });
  }

  static void showTips({
    int duration = 2000,
    required Widget child,
    double? height,
    Color? color,
  }) async {
    OverlayState overlayState = globalNavigatorKey.currentState!.overlay!;
    _startedTimeTips = DateTime.now();
    int time = 100;
    if (_overlayEntryTips == null) {
      _overlayEntryTips = OverlayEntry(builder: (BuildContext context) {
        double heightT = height ?? 44;
        heightT += MediaQuery.of(context).padding.top;
        return Align(
          alignment: Alignment.topCenter,
          child: Material(
            child: AnimatedContainer(
              duration: Duration(milliseconds: time),
              curve: Curves.easeIn,
              color: color ?? Color(0xff1E6FFF),
              padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
              height: _showingTips ? heightT : 0,
              child: Center(
                child: child,
              ),
            ),
          ),
        );
      });
      Future.delayed(Duration.zero, () {
        overlayState.insert(_overlayEntryTips!);
      });
    } else {
      if (_overlayEntryTips != null) {
        Future.delayed(Duration.zero, () {
          _showingTips = false;
          _overlayEntryTips?.markNeedsBuild();
          _overlayEntryTips?.remove();
          _overlayEntryTips = null;
          showTips(
              duration: duration, child: child, height: height, color: color);
        });
      }
    }
    Future.delayed(Duration(milliseconds: time), () {
      if (_overlayEntryTips != null) {
        _showingTips = true;
        _overlayEntryTips?.markNeedsBuild();
      }
    });
    Future.delayed(Duration(milliseconds: duration), () {
      if (DateTime.now().difference(_startedTimeTips!).inMilliseconds >=
          duration) {
        _showingTips = false;
        if (_overlayEntryTips != null) {
          _overlayEntryTips?.markNeedsBuild();
          Future.delayed(Duration(milliseconds: time), () async {
            if (_overlayEntryTips != null) {
              _overlayEntryTips?.markNeedsBuild();
              _overlayEntryTips?.remove();
              _overlayEntryTips = null;
            }
          });
        }
      }
    });
  }

  static void closeTips() {
    _showingTips = false;
    if (_overlayEntryTips != null) {
      Future.delayed(Duration.zero, () {
        _overlayEntryTips?.markNeedsBuild();
        _overlayEntryTips?.remove();
        _overlayEntryTips = null;
      });
    }
  }
}

class LoadingWidget extends StatefulWidget {
  const LoadingWidget({
    Key? key,
  }) : super(key: key);

  @override
  _LoadingWidgetState createState() => _LoadingWidgetState();
}

class _LoadingWidgetState extends State<LoadingWidget>
    with SingleTickerProviderStateMixin {
  AnimationController? _controller;

  @override
  void initState() {
    _controller =
        AnimationController(duration: Duration(milliseconds: 800), vsync: this)
          ..repeat();
    super.initState();
  }

  @override
  void dispose() {
    _controller?.dispose();
    _controller = null;
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return RotationTransition(
      alignment: Alignment.center,
      turns: _controller!,
      child: SizedBox(
        width: 28,
        height: 28,
//        child: Image.asset(AssetsConstant.images_img_loading),
      ),
    );
  }
}

class BlurRectWidget extends StatelessWidget {
  final Widget child;
  final Color? color;
  final double radius;
  final double sigmaX;
  final double sigmaY;

  BlurRectWidget(
      {required this.child,
      this.color,
      this.radius = 10,
      this.sigmaX = 20,
      this.sigmaY = 20});

  @override
  Widget build(BuildContext context) {
    return Container(
      child: ClipRRect(
        borderRadius: BorderRadius.all(Radius.circular(radius)),
        child: BackdropFilter(
          filter: ImageFilter.blur(
            sigmaX: sigmaX,
            sigmaY: sigmaY,
          ),
          child: Container(
            color: color,
            child: child,
          ),
        ),
      ),
    );
  }
}
""";
